package com.example.easytts.service

import com.example.easytts.repository.IpUsageRepository
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import java.time.LocalDate

@Service
class IpUsageCleanupService(
    private val ipUsageRepository: IpUsageRepository
) {
    // 每天凌晨0点执行
    @Scheduled(cron = "0 0 0 * * ?")
    fun resetIpUsageDaily() {
        val today = LocalDate.now().toString()
        val todayUsages = ipUsageRepository.findByUsageDayStr(today)
        todayUsages.forEach { usage ->
            usage.characterCount = 0
        }
        ipUsageRepository.saveAll(todayUsages)
    }
} 